package com.supreme.aspectserver.utils;

import com.supreme.aspectserver.component.BaseCache;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class StringCacheUtils implements BeanFactoryPostProcessor, ApplicationContextAware {

    /** Spring应用上下文环境 */
    private static ConfigurableListableBeanFactory beanFactory;

    private static ApplicationContext applicationContext;

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        StringCacheUtils.beanFactory = configurableListableBeanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        StringCacheUtils.applicationContext = applicationContext;
    }

    public static BaseCache getBaseCacheBean() {
        return StringCacheUtils.beanFactory.getBean(BaseCache.class);
    }
}
